n = int(input())
if len(str(n))==4:
    a=[]
    b=str(n)
    for i in range(len(b)-1):
        for g in range(i,len(b)):
            a.append(int(b[i:g+1]))
    k=[]
    for i in a:
        s=0
        for g in range(2,i):
            if i%g==0:
                s+=1
        if s==0:
            k.append(i)
    if len(k)>0:
        print(max(k))
    else:
        print("0")
else:
    print("0")